﻿using System;
using System.Web.UI.WebControls;
using BIS.Portal.Core.Base;
using BIS.Portal.Core.Global;
using System.Collections.Generic;
using BIS.Portal.Modules.CMS.BO;
using BIS.Portal.Modules.CMS.Entity;


namespace BIS.Portal.Modules.CMS
{
    public partial class CmsArticleByHotNewControl_Settings : ControlSettingBase
    {
        #region Lấy dữ liệu settings
        private string NoiDungHienThi
        {
            get { return GetControlSetting<string>(ModuleSettingNames.CmsArticleByHotNew.DDLNoiDungHienthi, PortalContext.LanguageAlias); }
        }
        private bool LocQueryString
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLLocTheoQuery, PortalContext.LanguageAlias); }
        }
        private bool HienThiTinNoiBatB
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLTinNoiBatHot, PortalContext.LanguageAlias); }
        }
        private bool HienThiAnhMinhHoaTinNoiBat
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLAnhMinhHoaHot, PortalContext.LanguageAlias); }
        }
        private bool HienThiMotaTinNoiBat
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLMieuTaHot, PortalContext.LanguageAlias); }
        }
        private bool HienThiLinkCtTinNoiBat
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLHienThiLinkHot, PortalContext.LanguageAlias); }
        }
        private bool HienThiTinMoiB
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLTinMoi, PortalContext.LanguageAlias); }
        }
        private bool HienThiAnhMinhHoaTinMoiB
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLAnhMinhHoaTinMoi, PortalContext.LanguageAlias); }
        }
        private bool HienThiMotaTinMoiB
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLHienThiMotaTinMoi, PortalContext.LanguageAlias); }
        }
        private bool HienThiLinkCtTinMoiB
        {
            get { return GetControlSetting<bool>(ModuleSettingNames.CmsArticleByHotNew.DDLHienThiLinkTinMoi, PortalContext.LanguageAlias); }
        }
        private int SoLuongHienThiTinNoiBat
        {
            get { return GetControlSetting<int>(ModuleSettingNames.CmsArticleByHotNew.DDLSoLuongTinHot, PortalContext.LanguageAlias); }
        }
        private int SoLuongHienThiTinMoi
        {
            get { return GetControlSetting<int>(ModuleSettingNames.CmsArticleByHotNew.DDLSoluongTinMoi, PortalContext.LanguageAlias); }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }
        #region Load dữ liệu vào Dropdownlist Category
        private void loadDDLNoiDungRoot()
        {
            int LanguageInUseId = PortalContext.LanguageInUseId;
            IList<ClientCmsArticleCategoryAndCategoryEntity> list =
            ClientCmsArticleCategoryAndCategoryBO.GetCategoryName(0, LanguageInUseId);
            ddlLoaiNoiDung.Items.Clear();
            ListItem itemDefault = new ListItem("---Không Lựa chọn---", "0");
            ddlLoaiNoiDung.Items.Add(itemDefault);
            for (int i = 0; i < list.Count; i++)
            {
                ListItem item = new ListItem(list[i].Category_name, list[i].Category_id.ToString());
                ddlLoaiNoiDung.Items.Add(item);
                loadDDLNoiDungChild(list[i].Category_id, "...", LanguageInUseId);
            }
        }
        private void loadDDLNoiDungChild(int iParentId, string sSeparator, int iLanguageInUseId)
        {
            IList<ClientCmsArticleCategoryAndCategoryEntity> listChild =
            ClientCmsArticleCategoryAndCategoryBO.GetCategoryName(iParentId, iLanguageInUseId);
            for (int i = 0; i < listChild.Count; i++)
            {
                ListItem item = new ListItem(sSeparator + listChild[i].Category_name, listChild[i].Category_id.ToString());
                ddlLoaiNoiDung.Items.Add(item);
                loadDDLNoiDungChild(listChild[i].Category_id, sSeparator + "...", iLanguageInUseId);
            }
        }
        #endregion

        private void LoadData()
        {
            //loadData noi dung
            loadDDLNoiDungRoot();

            //Binđ data controls setting
            if (!string.IsNullOrEmpty(NoiDungHienThi))
                ddlLoaiNoiDung.SelectedValue = NoiDungHienThi;
            ddLocQueryString.SelectedIndex = LocQueryString ? 0 : 1;
            ddlTinNoiBat.SelectedIndex = HienThiTinNoiBatB ? 0 : 1;
            txtSlTinNoiBat.Text = Convert.ToString(SoLuongHienThiTinNoiBat);
            ddlAnhMinhHoaTinNoiBat.SelectedIndex = HienThiAnhMinhHoaTinNoiBat ? 0 : 1;
            ddlMoTaTinNoiBat.SelectedIndex = HienThiMotaTinNoiBat ? 0 : 1;
            ddlLinkXemCTTinNoiBat.SelectedIndex = HienThiLinkCtTinNoiBat ? 0 : 1;
            ddlHienThiTinMoi.SelectedIndex = HienThiTinMoiB ? 0 : 1;
            txtSlTinMoi.Text = Convert.ToString(SoLuongHienThiTinMoi);
            ddlMoTaTinMoi.SelectedIndex = HienThiMotaTinMoiB ? 0 : 1;
            ddlAnhMinhHoaTinMoi.SelectedIndex = HienThiAnhMinhHoaTinMoiB ? 0 : 1;
            ddlLinkCTTinMoi.SelectedIndex = HienThiLinkCtTinMoiB ? 0 : 1;

        }

        public override void SaveSettings(Dictionary<string, string> settings)
        {

            SetControlSettingForAllLanguages(ddlLoaiNoiDung.ID, ModuleSettingNames.CmsArticleByHotNew.DDLNoiDungHienthi, settings);
            SetControlSettingForAllLanguages(ddLocQueryString.ID, ModuleSettingNames.CmsArticleByHotNew.DDLLocTheoQuery, settings);
            SetControlSettingForAllLanguages(ddlTinNoiBat.ID, ModuleSettingNames.CmsArticleByHotNew.DDLTinNoiBatHot, settings);
            SetControlSettingForAllLanguages(txtSlTinNoiBat.ID, ModuleSettingNames.CmsArticleByHotNew.DDLSoLuongTinHot, settings);
            SetControlSettingForAllLanguages(ddlAnhMinhHoaTinNoiBat.ID, ModuleSettingNames.CmsArticleByHotNew.DDLAnhMinhHoaHot, settings);
            SetControlSettingForAllLanguages(ddlMoTaTinNoiBat.ID, ModuleSettingNames.CmsArticleByHotNew.DDLMieuTaHot, settings);
            SetControlSettingForAllLanguages(ddlLinkXemCTTinNoiBat.ID, ModuleSettingNames.CmsArticleByHotNew.DDLHienThiLinkHot, settings);
            SetControlSettingForAllLanguages(ddlHienThiTinMoi.ID, ModuleSettingNames.CmsArticleByHotNew.DDLTinMoi, settings);
            SetControlSettingForAllLanguages(txtSlTinMoi.ID, ModuleSettingNames.CmsArticleByHotNew.DDLSoluongTinMoi, settings);
            SetControlSettingForAllLanguages(ddlAnhMinhHoaTinMoi.ID, ModuleSettingNames.CmsArticleByHotNew.DDLAnhMinhHoaTinMoi, settings);
            SetControlSettingForAllLanguages(ddlMoTaTinMoi.ID, ModuleSettingNames.CmsArticleByHotNew.DDLHienThiMotaTinMoi, settings);
            SetControlSettingForAllLanguages(ddlLinkCTTinMoi.ID, ModuleSettingNames.CmsArticleByHotNew.DDLHienThiLinkTinMoi, settings);

        }

    }
}